function P = gen_modify_mat(H,row_idx)
% function P = gen_modify_mat(H,row_idx)
% this function generate the global modify matrix P with smoothness
% condition H. It divide into two main steps: first, elliminate the
% multiple level constrains(include edge constrain and node constrains
% related with each hanging node). Second, add identity matrix.
[m,n] = size(H);
% m is the number of constrains , and n is the total degree of freedom
[H_i,H_j,H_s] = find(H); len = length(H_i);
P_i = zeros(len+n,1); P_j = zeros(len+n,1); P_s = zeros(len+n,1);
P_i(1:len) = row_idx(H_i); P_j(1:len) = H_j; P_s(1:len) = H_s;
P_i(len+1:len+n) = 1:n; P_j(len+1:len+n) = 1:n;
P_s(len+1:len+n) = 1;
P = sparse(P_i,P_j,P_s);